<?php
/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/6/16
 * Time: 上午11:27
 */

namespace app\src\platform\logic;


use app\src\base\helper\ExceptionHelper;
use app\src\base\logic\BaseLogic;
use app\src\platform\model\PlatformAdmin;
use think\Exception;
use think\exception\DbException;

class PlatformAdminLogic extends BaseLogic
{
    protected function _init()
    {
        $this->setModel(new PlatformAdmin());
    }


    /**
     * 获取平台管理员所有平台
     * @param $uid
     * @param $group_id
     * @return array
     */
    public function getAdminPlatform($uid, $group_id = false)
    {
        try{
            $map = [
                'pa.uid' => $uid,
                'p.status' => 0
            ];

            if($group_id){
                $map['p.group_id'] = $group_id;
            }

            $model = $this->getModel();

            $result = $model->alias('pa')->join('__PLATFORM__ p', 'pa.platform_id = p.id')
                ->where($map)->select();

            return $this->apiReturnSuc($result);
        }catch (DbException $ex){
            return $this->apiReturnErr(ExceptionHelper::getErrorString($ex));
        }
    }
}